﻿using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace HorrorEncodeDesktop {
    /// <summary>
    /// Lógica de interacción para MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }

        /// <summary>
        /// Cambiar el Pivot en foco a "ocultar" 
        /// </summary>
        private void Pivot_Encode_Click(object sender, MouseButtonEventArgs e) {
            EncodePivot.Foreground = Brushes.White;
            DecodePivot.Foreground = Brushes.DarkGray;

            EncodeGrid.Visibility = System.Windows.Visibility.Visible;
            DecodeGrid.Visibility = System.Windows.Visibility.Collapsed;
        }

        /// <summary>
        /// Cambiar el Pivot en foco a "recuperar" 
        /// </summary>
        private void Pivot_Decode_Click(object sender, MouseButtonEventArgs e) {
            EncodePivot.Foreground = Brushes.DarkGray;
            DecodePivot.Foreground = Brushes.White;

            EncodeGrid.Visibility = System.Windows.Visibility.Collapsed;
            DecodeGrid.Visibility = System.Windows.Visibility.Visible;
        }

        /// <summary>
        /// Codificar el Mensaje
        /// </summary>
        private void Encode_Click(object sender, RoutedEventArgs e) {
            try {
                MessageEncoded.Text = HorrorEncodeLib.Encode.ToString(MessageToEncode.Text, MessageCarrier.Text);
            } catch ( Exception ex ) {
                MessageBox.Show(ex.Message);
                return; // Evitar que se haga la evaluación de abajo
            }

            if ( HorrorEncodeLib.Encode.RemainingChars > 0 )
                MessageBox.Show("Faltan " + HorrorEncodeLib.Encode.RemainingChars.ToString() + " carácteres para codificar todo el mensaje.");
        }

        /// <summary>
        /// Decodificar el mensaje
        /// </summary>
        private void Decode_Click(object sender, RoutedEventArgs e) {
            try {
                MessageDecoded.Text = HorrorEncodeLib.Decode.FromString(MessageToDecode.Text);
            } catch ( Exception ex ) {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
